﻿using System;
using System.Collections.Generic;
using System.Text;
using DevExpress.XtraEditors;
using System.Windows.Forms;
using VietKinsNutrition.Data;
using System.Data;
using VietKinsNutrition.Common;

namespace VietKinsNutrition.Bussiness
{
    public class ClsTblDm_KhoilopBLL : ClsBindingBLL
    {
        public void FocusControl(TextBox Textbox, DataGridView Grid)
        {
            Textbox.Focus();
            Grid.Enabled = !Grid.Enabled;
        }
        int id;

        public int Id
        {
            get { return id; }
            set { id = value; }
        }

        ClsTblDm_KhoilopDAL ClsTblDm_KhoilopdalAcc = new ClsTblDm_KhoilopDAL();

        public void ClearControl(TextBox TextBox)
        {
            TextBox.Text = "";
        }
        private DataTable ReturnDataTable_All()
        {
           return ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];
        }
        public void Bind_Cbo(ComboBoxEdit Cbo)
        {
            UserComboBoxItem.SetItem(Cbo, ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0], "Id", "Tenkhoilop");
            UserComboBoxItem.SelectItem(Cbo, "1");
            //Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];
            //Cbo.ValueMember = "Id";
            //Cbo.DisplayMember = "Tenkhoilop";
        }
        public DataTable GetTable()
        {
            return ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];
        }
        public BindingSource Bind_khoilop()
        {
            string NamePrc = "SELECT Id, Tenkhoilop FROM TblDm_Khoilop ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_quanhe()
        {
            string NamePrc = "SELECT * FROM TblDm_quanhe ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_loaihinhdaotao()
        {
            string NamePrc = "SELECT * FROM TblDm_Loaihinhdaotao ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_loaihopdong()
        {
            string NamePrc = "SELECT * FROM TblDm_Loaihopdong ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_hedaotao()
        {
            string NamePrc = "SELECT * FROM TblDm_Hedaotao ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_dmtaisan()
        {
            string NamePrc = "SELECT * FROM TblDm_Loaitaisan ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public void BingSource_DataGrid(DataGridView GridView)
        {
            GridView.DataSource = ReturnDataTable_All();
        }
        public void BingSource_InputControl(TextBox Textbox, DataGridView Grid)
        {
            if (Grid.RowCount > 0)
            {
                this.Id = int.Parse(Grid.Rows[Grid.CurrentRow.Index].Cells["Id"].Value.ToString());
                Textbox.Text = Grid.Rows[Grid.CurrentRow.Index].Cells["Tenkhoilop"].Value.ToString();
            }
        }

        public void Insert(string Ten)
        {
            ClsTblDm_KhoilopdalAcc.Insert(Ten);
        }

        public void Edit(int Id, string Ten)
        {
            this.ClsTblDm_KhoilopdalAcc.Edit(Id, Ten);
        }

        public void Del()
        {
            ClsTblDm_KhoilopdalAcc.Del(Id);
        }

        public bool FindSameName(int iBtn, string VarTen)
        {
            bool Value = false;
            DataTable dt;
            dt = ClsTblDm_KhoilopdalAcc.FindSameName(VarTen).Tables[0];
            switch (iBtn)
            {
                case 1:
                    {
                        if (dt.Rows.Count >= 1)
                        {
                            XtraMessageBox.Show("Không cho phép thêm trùng dữ liệu", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Question);
                            Value = false;
                        }
                        else
                        {
                            Value = true;
                        }
                        break;
                    }
                case 2:
                    {
                        if (dt.Rows.Count == 0)
                        {
                            return true;
                        }
                        DataRow Row = dt.Rows[0];

                        if (dt.Rows.Count >= 1 && this.Id != int.Parse(Row["Id"].ToString()))
                        {
                            XtraMessageBox.Show("Tên không cho phép trùng", "Chú ý", MessageBoxButtons.OK, MessageBoxIcon.Question);
                            Value = false;
                        }
                        else
                        {
                            Value = true;
                        }
                        break;
                    }
            }
            return Value;
        }


        public BindingSource Bind_phonghoc()
        {
            string NamePrc = "SELECT * FROM Tblphonghoc ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_ctgd()
        {
            string NamePrc = "SELECT * FROM TblDm_ChuongtrinhGD ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_dotuoi()
        {
            string NamePrc = "SELECT * FROM TblDm_Dotuoi ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
        public BindingSource Bind_loailop()
        {
            string NamePrc = "SELECT * FROM TblDm_Phanloailop ";

            BindingSource Binding = this.BingSource(NamePrc, "TblDm_khoilop");
            return Binding;
            //     Cbo.DataSource = ClsTblDm_KhoilopdalAcc.SelectAll().Tables[0];

        }
    }
}
